﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EffiProz.Core.Lib;
using EffiProz.Core.DataTypes;
using EffiProz.Core.Errors;

namespace EffiProz.Core.RowIO
{
    public class RowInputBinary180 : RowInputBinary
    {
        public RowInputBinary180(byte[] buf)
            : base(buf)
        {
        }

        protected override TimeData readTime(SqlType type)
        {

            if (type.typeCode == Types.SQL_TIME)
            {
                long millis = readLong();
                return new TimeData((int)(millis / 1000), 0, 0);
            }
            else
            {
                return new TimeData(readInt(), readInt(), readInt());
            }
        }

        protected override TimestampData readDate(SqlType type)
        {

            long millis = readLong();

            return new TimestampData(millis / 1000);
        }

        protected override TimestampData readTimestamp(SqlType type)
        {

            if (type.typeCode == Types.SQL_TIMESTAMP)
            {
                long millis = readLong();
                return new TimestampData(millis / 1000, readInt());
            }
            else
            {
                return new TimestampData(readLong(), readInt(), readInt());
            }
        }
    }
}
